/*
 * Copyright (c) 2010 Andy Aspell-Clark
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package uk.co.droidinactu.heartratemonitor;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import uk.co.droidinactu.common.view.MyAbstractApplication;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;

/**
 * 
 * @author andy
 * 
 */
public final class HeartRateMonitorApplication extends MyAbstractApplication {

	public static String LOG_TAG = "HeartRateMonitor:";

	public int nbrGridCols = 4;
	public int nbrGridRows = 10;

	public final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	public ArrayList<ArrayList<String>> tagLevels = new ArrayList<ArrayList<String>>();

	@Override
	public String getApplicationAuthor() {
		return this.getString(R.string.app_author);
	}

	@Override
	public String getApplicationAuthorEmail() {
		return this.getString(R.string.about_email);
	}

	@Override
	public String getApplicationAuthorWebsite() {
		return this.getString(R.string.about_website_url);
	}

	@Override
	public String getApplicationDescription() {
		return this.getString(R.string.app_explanation);
	}

	@Override
	public Bitmap getApplicationImage() {
		return BitmapFactory.decodeResource(getResources(), R.drawable.heart_rate);
	}

	@Override
	public String getApplicationName() {
		return this.getString(R.string.app_name);
	}

	@Override
	public String getApplicationVersion() {
		return getAppVersion("uk.co.droidinactu.bibliotheca");
	}

	@Override
	public String getLogTag() {
		return LOG_TAG;
	}

	public String getPayPalDonateName() {
		return "HeartRateMonitor";
	}

	public final String getSdCardDir() {
		final File extDir = Environment.getExternalStorageDirectory();
		return extDir.getPath() + File.separator;
	}

	/**
	 * @return the simple date format ["yyyy-MM-dd"]
	 */
	@Override
	public final SimpleDateFormat getSimpleDateFmt() {
		return sdf;
	}

	public Boolean isSdAvailable() {
		boolean mExternalStorageAvailable = false;
		boolean mExternalStorageWriteable = false;

		final String state = Environment.getExternalStorageState();

		if (Environment.MEDIA_MOUNTED.equals(state)) {
			// We can read and write the media
			mExternalStorageAvailable = mExternalStorageWriteable = true;
		} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
			// We can only read the media
			mExternalStorageAvailable = true;
			mExternalStorageWriteable = false;
		} else {
			// Something else is wrong. It may be one of many other states, but
			// all we need
			// to know is we can neither read nor write
			mExternalStorageAvailable = mExternalStorageWriteable = false;
		}
		return mExternalStorageAvailable;
	}

}
